<template>
  <div>
    <van-tabbar v-model="active" active-color="#76AA28">
      <van-tabbar-item icon="home-o" to="/">首页</van-tabbar-item>
      <van-tabbar-item icon="search" to="/square">广场</van-tabbar-item>
      <van-tabbar-item to="/release-goods"
        ><div class="bg-g">+</div></van-tabbar-item
      >
      <van-tabbar-item icon="chat-o" to="/message">消息</van-tabbar-item>
      <van-tabbar-item icon="user-o" @click="handleMineClick"
        >我的</van-tabbar-item
      >
    </van-tabbar>
  </div>
</template>
<script>
import { ref } from 'vue'
import { Tabbar, TabbarItem, Image as VanImage } from 'vant'
import { useRouter } from 'vue-router'
// import routerURL from '@/router/routerURL'

export default {
  name: 'MyTabbar',
  components: {
    [Tabbar.name]: Tabbar,
    [TabbarItem.name]: TabbarItem,
    [VanImage.name]: VanImage,
  },
  setup() {
    const active = ref(0)
    const router = useRouter()
    const handleMineClick = () => {
      const token = window.localStorage.getItem('token')
      if (!token) {
        // 如果本地存储中没有 token，则跳转到登录页面
        router.push({ path: '/login' })
      } else {
        // 如果存在 token，则继续跳转到 "我的" 页面
        router.push({ path: '/mine' })
      }
    }
    return { active, handleMineClick }
  },
}
</script>
<style></style>
